import request from '@/utils/request'

export function getAgentList(data) {
    return request({
        url: '/hosts/list',
        method: 'get',
        params: data
    })
}

export function uninstallAgent(data) {
    return request({
        url: '/hosts/delete',
        method: 'delete',
        data
    })
}

export function upgradeAgent(data) {
    return request({
        url: '/hosts/update',
        method: 'put',
        data
    })
}

export function systemCompare(data) {
    return request({
        url: '/hosts/compare',
        method: 'post',
        params: data
    })
}

export function diffPackage(data) {
    return request({
        url: '/hosts/comparePackages',
        method: 'post',
        params: data
    })
}

export function downloadCompare(data) {
    return request({
        url: '/hosts/compare',
        method: 'get',
        responseType: 'blob',
        params: data
    })
}

export function exportHosts(data) {
    return request({
        url: '/hosts/export',
        method: 'post',
        responseType: 'blob',
        data
    })
}

export function getConfigureHost({ page, perPage, paged=false, search, sortBy, sortOrder, ...data }) {
    let url = `?page=${page}&perPage=${perPage}&search=${search? search : ""}&paged=${paged}&sortBy=${sortBy}&sortOrder=${sortOrder}`
    let configureObj = [...data.configureObj];
    if (data.configure) {
        configureObj.push(
            {
                name: data.configure,
                compare: data.rule,
                value: data.compare_value
            }
        )
    }
    return request({
        url: '/hosts/list/filter/config' + url,
        method: 'post',
        data: configureObj
    })
}

export function getAgentVersionList() {
    return request({
        url: '/hosts/versionList',
        method: 'get'
    })
}

export function getAgentVersionHost({ page, perPage, paged, search, sortBy, sortOrder, ...data }) {
    const params = {page, perPage, paged, search, sortBy, sortOrder, version: data.agentVersion, compare: data.rule };
    return request({
        url: '/hosts/hostVersion',
        method: 'get',
        params
    })
}

export function downloadComparePackage(data) {
    return request({
        url: '/hosts/comparePackage',
        method: 'get',
        responseType: 'blob',
        params: data
    })
}

export function downloadHosts(data) {
    return request({
        url: '/packagerecords/download',
        method: 'post',
        responseType: 'blob',
        data
    })
}